﻿using System;
namespace Producers.Ehr.Xtee.Riik.Ee.Producer.Ehr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="EN_OtsiDokumenti_response", Namespace="http://producers.ehr.xtee.riik.ee/producer/ehr", Target=typeof(ENOtsiDokumentiResponse))]
    public class ENOtsiDokumentiResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IENOtsiDokumentiResponse clazz;
        
        public ENOtsiDokumentiResponseSerializer(IENOtsiDokumentiResponse clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("EN_OtsiDokumenti");
            if (clazz.ENOtsiDokumenti!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute(">>>EN_OtsiDokumenti_response>EN_OtsiDokumenti>dokument", "http://producers.ehr.xtee.riik.ee/producer/ehr", clazz.ENOtsiDokumenti.Count);
                for (int x = 0; ((clazz.ENOtsiDokumenti != null) 
                            && (x < clazz.ENOtsiDokumenti.Count)); x = (x + 1)) {
                    if (clazz.ENOtsiDokumenti[x]!=null) {
                        Writer.WriteStartElement("dokument");
                        global::Xtee.Core.SerializationMetadata metaENOtsiDokumenti = this.GetMetaData(clazz.ENOtsiDokumenti[x]);
                        Writer.WriteTypeAttribute(metaENOtsiDokumenti.TypeQualifiedName.Namespace, metaENOtsiDokumenti.TypeQualifiedName.Name);
                        metaENOtsiDokumenti.NewSerializer(clazz.ENOtsiDokumenti[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ENOtsiDokumenti");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="EN_OtsiDokumenti") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>EN_OtsiDokumenti_response>EN_OtsiDokumenti");
                }
                clazz.ENOtsiDokumenti = new System.Collections.Generic.List<ENOtsiDokumentiResponse.IENOtsiDokumentiType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("EN_OtsiDokumenti");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "dokument")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>EN_OtsiDokumenti_response>EN_OtsiDokumenti>dokument");
                        }
                        global::Xtee.Core.SerializationMetadata metaENOtsiDokumenti = this.GetMetaData<ENOtsiDokumentiResponse.IENOtsiDokumentiType>(Reader, ">>>EN_OtsiDokumenti_response>EN_OtsiDokumenti>dokument", "http://producers.ehr.xtee.riik.ee/producer/ehr");
                        ENOtsiDokumentiResponse.IENOtsiDokumentiType item = metaENOtsiDokumenti.NewEntity<ENOtsiDokumentiResponse.IENOtsiDokumentiType>();
                        clazz.ENOtsiDokumenti.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("dokument");
                            metaENOtsiDokumenti.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>EN_OtsiDokumenti_response>EN_OtsiDokumenti", Reader.LocalName);
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>>EN_OtsiDokumenti_response>EN_OtsiDokumenti>dokument", Namespace="http://producers.ehr.xtee.riik.ee/producer/ehr", Target=typeof(ENOtsiDokumentiResponse.ENOtsiDokumentiType))]
        public class ENOtsiDokumentiTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected ENOtsiDokumentiResponse.IENOtsiDokumentiType clazz;
            
            public ENOtsiDokumentiTypeSerializer(ENOtsiDokumentiResponse.IENOtsiDokumentiType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                if (clazz.Id!=null) {
                    Writer.WriteStartElement("id");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Id))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.DokNr!=null) {
                    Writer.WriteStartElement("dok_nr");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DokNr))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.DokKp!=null) {
                    Writer.WriteStartElement("dok_kp");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DokKp))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.EdastKp!=null) {
                    Writer.WriteStartElement("edast_kp");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.EdastKp))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Muutja!=null) {
                    Writer.WriteStartElement("muutja");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Muutja))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.MuutmiseAeg!=null) {
                    Writer.WriteStartElement("muutmise_aeg");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.MuutmiseAeg))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.DateCreated!=null) {
                    Writer.WriteStartElement("date_created");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DateCreated))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.AnesId!=null) {
                    Writer.WriteStartElement("anes_id");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.AnesId))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Omavalitsus!=null) {
                    Writer.WriteStartElement("omavalitsus");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Omavalitsus))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Maakond!=null) {
                    Writer.WriteStartElement("maakond");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Maakond))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Staatus!=null) {
                    Writer.WriteStartElement("staatus");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Staatus))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.StaatusTxt!=null) {
                    Writer.WriteStartElement("staatus_txt");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.StaatusTxt))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Markused!=null) {
                    Writer.WriteStartElement("markused");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Markused))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.AnesIdTxt!=null) {
                    Writer.WriteStartElement("anes_id_txt");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.AnesIdTxt))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.DotyKood!=null) {
                    Writer.WriteStartElement("doty_kood");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DotyKood))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.DotyNimetus!=null) {
                    Writer.WriteStartElement("doty_nimetus");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DotyNimetus))).ToString());
                    Writer.WriteEndElement();
                }
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="id") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiDokumenti_response>EN_OtsiDokumenti>dokument>id");
                    }
                    clazz.Id = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("id")).Value;
                }
                if (Reader.LocalName=="dok_nr") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiDokumenti_response>EN_OtsiDokumenti>dokument>dok_nr");
                    }
                    clazz.DokNr = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("dok_nr")).Value;
                }
                if (Reader.LocalName=="dok_kp") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiDokumenti_response>EN_OtsiDokumenti>dokument>dok_kp");
                    }
                    clazz.DokKp = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("dok_kp")).Value;
                }
                if (Reader.LocalName=="edast_kp") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiDokumenti_response>EN_OtsiDokumenti>dokument>edast_kp");
                    }
                    clazz.EdastKp = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("edast_kp")).Value;
                }
                if (Reader.LocalName=="muutja") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiDokumenti_response>EN_OtsiDokumenti>dokument>muutja");
                    }
                    clazz.Muutja = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("muutja")).Value;
                }
                if (Reader.LocalName=="muutmise_aeg") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiDokumenti_response>EN_OtsiDokumenti>dokument>muutmise_aeg");
                    }
                    clazz.MuutmiseAeg = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("muutmise_aeg")).Value;
                }
                if (Reader.LocalName=="date_created") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiDokumenti_response>EN_OtsiDokumenti>dokument>date_created");
                    }
                    clazz.DateCreated = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("date_created")).Value;
                }
                if (Reader.LocalName=="anes_id") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiDokumenti_response>EN_OtsiDokumenti>dokument>anes_id");
                    }
                    clazz.AnesId = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("anes_id")).Value;
                }
                if (Reader.LocalName=="omavalitsus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiDokumenti_response>EN_OtsiDokumenti>dokument>omavalitsus");
                    }
                    clazz.Omavalitsus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("omavalitsus")).Value;
                }
                if (Reader.LocalName=="maakond") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiDokumenti_response>EN_OtsiDokumenti>dokument>maakond");
                    }
                    clazz.Maakond = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("maakond")).Value;
                }
                if (Reader.LocalName=="staatus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiDokumenti_response>EN_OtsiDokumenti>dokument>staatus");
                    }
                    clazz.Staatus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("staatus")).Value;
                }
                if (Reader.LocalName=="staatus_txt") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiDokumenti_response>EN_OtsiDokumenti>dokument>staatus_txt");
                    }
                    clazz.StaatusTxt = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("staatus_txt")).Value;
                }
                if (Reader.LocalName=="markused") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiDokumenti_response>EN_OtsiDokumenti>dokument>markused");
                    }
                    clazz.Markused = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("markused")).Value;
                }
                if (Reader.LocalName=="anes_id_txt") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiDokumenti_response>EN_OtsiDokumenti>dokument>anes_id_txt");
                    }
                    clazz.AnesIdTxt = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("anes_id_txt")).Value;
                }
                if (Reader.LocalName=="doty_kood") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiDokumenti_response>EN_OtsiDokumenti>dokument>doty_kood");
                    }
                    clazz.DotyKood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("doty_kood")).Value;
                }
                if (Reader.LocalName=="doty_nimetus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiDokumenti_response>EN_OtsiDokumenti>dokument>doty_nimetus");
                    }
                    clazz.DotyNimetus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("doty_nimetus")).Value;
                }
            }
        }
    }
}
